package com.yxdj.user.controller;


import com.yxdj.common.core.web.controller.BaseController;
import com.yxdj.common.core.web.domain.AjaxResult;
import com.yxdj.common.security.annotation.RequiresPermissions;
import com.yxdj.user.domain.Region;
import com.yxdj.user.service.IRegionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地区信息Controller
 *
 * @author mty
 * @date 2025-03-18
 */
@Tag(name = "地区信息管理")
@RestController
@RequestMapping("/region")
public class RegionController extends BaseController
{
    @Autowired
    private IRegionService regionService;

    /**
     * 查询地区信息列表
     */
    @Operation(summary = "查询地区信息列表")
    @RequiresPermissions("user:region:list")
    @GetMapping("/list")
    public AjaxResult list(Region region)
    {
        List<Region> list = regionService.selectRegionList(region);
        return success(list);
    }

    /**
     * 根据父编码获取所有地区信息
     */
    @Operation(summary = "根据父编码获取所有地区信息")
    @RequiresPermissions("user:region:query")
    @GetMapping(value = "/parentCode")
    public AjaxResult getInfo(@Parameter(name = "parentCode" ,required = true, description = "父编码") @PathVariable("parentCode") Long parentCode)
    {
        return success(regionService.selectRegionListByParentId(parentCode));
    }
}
